<?php
/**
 * Fastapp.
 * 3/7/24
 * @Author deepsea
 * @Contact telegram:deepsea159 
 */

declare(strict_types=1);

namespace App\Fastapp\Api\Controller;

use Hyperf\Di\Annotation\Inject;
use Hyperf\Validation\Contract\ValidatorFactoryInterface;
use Mine\MineApi;
use Psr\Container\ContainerInterface;
use Psr\Http\Message\ResponseInterface;

class ApiController extends MineApi
{
    #[Inject]
    protected ContainerInterface $container;

    #[Inject]
    protected ValidatorFactoryInterface $validatorFactory;

    public function validate(array $rule, array $message = []): array
    {
        return $this->validatorFactory->make($this->request->all(), $rule, $message)->validate();
    }

    public function success(object|array|string|null $msgOrData = '', object|array $data = [], int $code = 200): ResponseInterface
    {
        if (is_array($msgOrData)) $msgOrData = $msgOrData ?: new \stdClass(); else $data = $data ?: new \stdClass();
        return parent::success($msgOrData, $data, $code);
    }
}
